<template>
  <div v-on:click="showpopup()">
    <mt-cell class="idselect" :title="label" v-model="currentValue" is-link></mt-cell>
  </div>
</template>
<script>
  /**
   * App component.
   * @module common/plugins/inputDateselect
   * @author sea
   * @description 上拉选日期组件，参数datepickerType有nyr为选择年月日的，ny为选择年月的
   * @example <inputDateselect name="起始日期" label="起始日期"
   datepickerType="ny"
   v-if="accounttype==='2' || accounttype==='3'"
   />
   默认为当前的时间
   v-model出參数的数据格式是"2017-10"
   */
  export default {
    data () {
      return {
        currentValue: this.value
      };
    },
    props: {
      value: {
        type: String,
        default: ''
      },
      label: {
        type: String,
        default: ''
      },
      datepickerType: {
        type: String,
        defalut: 'nyr'//分三个nyr年月日，ny年月，年y
      }
    },
    methods: {
      showpopup () {
        let self = this;
        let crtdate = new Date();
        let crtdatestr = crtdate.getFullYear() + '-' + (crtdate.getMonth() + 1) + '-' + (crtdate.getDate());
        if (this.datepickerType === 'nyr') {
          this.$store.dispatch('setDatePiker', {
            value: crtdatestr, //选日期默认选今天
            method: function (result) {
              self.currentValue = result.getFullYear() + '-' + (result.getMonth() + 1) + '-' + (result.getDate());
            }
          });
        } else if (this.datepickerType === 'ny') {
          this.$store.dispatch('setDatePickerym', {
            value: [crtdate.getFullYear(), crtdate.getMonth() + 1],
            method: function (result) {
              console.log(result);
              self.currentValue = result[0]['value'] + '-' + result[1]['value'];
            }
          });
        } else if (this.datepickerType === 'n') {
          this.$store.dispatch('setDatePickern', {
            value: [crtdate.getFullYear()],
            method: function (result) {
              self.currentValue = result[0]['value'];
            }
          });
        }
      }
    },
    watch: {
      value (val) {
        this.currentValue = val;
      },
      currentValue (val) {
        this.$emit('input', val);
      }
    }
  };
</script>
<style lang="scss">
  // .idselect.mint-cell:last-child{
  //background-image: none;
  // }
</style>

